//
//  SQStateViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/25.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "SQStateViewController.h"

#import "SQStateCell.h"
#import "ShopCenterViewController.h"
#import "MessViewController.h"
#import "DPZLViewController.h"
#import "SQRZViewController.h"
@interface SQStateViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSMutableArray *array;
    NSArray *arr;
}

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableDictionary *dic;
@end

@implementation SQStateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    [self showNav:@"申请入驻"];
    array = [NSMutableArray array];
    _dic = [NSMutableDictionary dictionary];
    arr = @[@"",@"房产商家",@"购车商家",@"干洗商家",@"开锁商家",@"果蔬商家",@"苦力商家",@"快递商家",@"家政商家",@"洗车商家",@"上户商家"];
    [self loadUI];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData2];
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    [self.view addSubview:_tableView];
    
}
#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    SQStateCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"SQStateCell" owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.btnBH.layer.borderWidth = 0.5;
    cell.btnBH.layer.borderColor = [UIColor redColor].CGColor;
    cell.btnBH.layer.cornerRadius = 5.0;
    [cell.btnBH addTarget:self action:@selector(clickBH) forControlEvents:UIControlEventTouchUpInside];
    
    cell.btnUpdate.layer.borderWidth = 1.0;
    cell.btnUpdate.layer.borderColor = [UIColor redColor].CGColor;
    cell.btnUpdate.layer.cornerRadius = 5.0;
    [cell.btnUpdate addTarget:self action:@selector(clickUpdate) forControlEvents:UIControlEventTouchUpInside];
    
    cell.labStyle.text = [_dic objectForKey:@"name"];
    NSString *merchType = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"merchanttype"] integerValue]];
    NSInteger inde = [merchType integerValue];
    cell.labStyle.text = arr[inde];
    
    NSString *date = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"applytime"] integerValue]];
    NSString *time = [self getNewDate:date];
    cell.labDate.text = time;
    NSString *toex = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"toexamine"] integerValue]];
    NSInteger index = [toex integerValue];
    if (index == 2) {
        cell.labState.text = @"审核中";
        cell.btnBH.hidden = YES;
        cell.btnUpdate.hidden = YES;
    }else if (index == 3){
        cell.labState.text = @"审核通过";
    }else if (index == 4){
        cell.labState.text = @"驳回";
    }else{
        cell.labState.text = @"回收";
    }
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 136.0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
//驳回
- (void)clickBH{
    MessViewController *mess = [[MessViewController alloc] init];
    [self.navigationController pushViewController:mess animated:YES];
}
//修改
- (void)clickUpdate{
    SQRZViewController *sqrz = [[SQRZViewController alloc] init];
    NSString *merid = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"id"] integerValue]];
    sqrz.merid = merid;//商家类型
    sqrz.className = [_dic objectForKey:@"name"];
    [self.navigationController pushViewController:sqrz animated:YES];
}

//我申请的商家
- (void)loadData2{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:token forKey:@"verifiToken"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/Forbusiness/mybusiness",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            _dic = [responseObject objectForKey:@"result"];
            [_tableView reloadData];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
